﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Spire.Pdf;
using Spire.Pdf.Annotations;
using Spire.Pdf.Annotations.Appearance;
using Spire.Pdf.Graphics;
using System.Windows.Forms;
using System.IO;
using SgAutoArchiveSp;
using System.Data.OleDb;
using DevExpress.XtraGrid.Views.Base;
using Spire.Xls;
using SgAutoArchiveBrrDal;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Controls;


namespace SgAotoArchiveSp
{
    public partial class Form1 : Form
    {
        RepositoryItemButtonEdit m_OperateFoodBtn = new RepositoryItemButtonEdit();
        private static int id;
        private List<SgAutoArchiveBrrDal.T_CARDINFO> _listCardinfo;
        private static string newstr;
        private List<SgAutoArchiveBrrDal.T_CARDINFO> _listSp;
        private static int istauts;
        private string poldaddr = "";
        private Bitmap _bit;
        private Bitmap _bit2;
       // private Bitmap _bit3;
        private byte[] _imagebytescard;
        private byte[] _imagebytesper;
        private byte[] _imagebytespdf;
        private string _sUPath = "";

        public Form1()
        {
            InitializeComponent();
            gridView_init();
            gridView1.RowCellClick += gridView1_RowCellClick;
            gridView1.CustomDrawCell += GridView1_CustomDrawCell;
            gridView1.CustomDrawRowIndicator += gridView1_CustomDrawRowIndicator;
            gridView1.RowCountChanged += gv_RowCountChanged;
            gridView1.CustomRowCellEdit += gridView1_CustomRowCellEdit;
        }

        protected override void WndProc(ref Message msg)
        {
            base.WndProc(ref msg);

            try
            {
                var aa = SgArchiveCommons.UDisk.GetRemovableDrivers(ref msg);
                if (aa == null || aa.Length < 1) return;

                var ds = string.Empty;
                for (int i = 0; i < aa.Length; i++)
                {
                    ds += aa[i]; // + Environment.NewLine;
                }
                ///
                _sUPath = ds;
                if (!_sUPath.EndsWith("\\"))
                    _sUPath = _sUPath + "\\";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
        {

            if (e.Column.FieldName == "审批状态")
            {
                if (e.CellValue == null)
                    return;
                DataRow row = gridView1.GetDataRow(e.RowHandle);
                if (row["审批状态"].ToString() == "尚未审批")
                {
                    e.RepositoryItem = m_OperateFoodBtn;

                }
            }

        }
        private void GridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {

            string content = "";
            if (e.Column.FieldName == "是否提交")
            {
                if (e.CellValue == null)
                    return;

                if (e.CellValue.ToString() == "1")
                {
                    content = "待审核";
                }
                else if (e.CellValue.ToString() == "2")
                {
                    content = "审核中";
                }
                else
                {
                    content = "审核结束";
                }

                e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
                e.DisplayText = content;
                if (content == "待审核")
                {
                    e.Appearance.BackColor = Color.Red;//设置此行的背景颜色}
                }
                if (content == "审核中")
                {
                    e.Appearance.BackColor = Color.Yellow;//设置此行的背景颜色}
                }
                if (content == "审核结束")
                {
                    e.Appearance.BackColor = Color.Green;//设置此行的背景颜色}
                }
                // gridControl1.RefreshDataSource();
            }
        }

        private void gridView_init()
        {

            this.button3.Visible = false;
            this.txt_bz.Visible = false;
            button4.Visible = false;
            if (_bit != null)
            {
                this.pictureBox1.Image = null;
                _bit.Dispose();
            }

            //this.pictureBox1.Image = null;
            if (_bit2 != null)
            {
                this.pictureBox2.Image = null;
                _bit2.Dispose();
            }
          
            
            gridView1.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect;
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("ID"));
            dt.Columns.Add(new DataColumn("登记日期"));
            dt.Columns.Add(new DataColumn("档案类型"));
            dt.Columns.Add(new DataColumn("是否提交"));
            dt.Columns.Add(new DataColumn("姓名"));
            dt.Columns.Add(new DataColumn("身份证号"));
            dt.Columns.Add(new DataColumn("性别"));
            dt.Columns.Add(new DataColumn("出生日期"));
            dt.Columns.Add(new DataColumn("户籍地址"));
            dt.Columns.Add(new DataColumn("所属派出所"));
            dt.Columns.Add(new DataColumn("身份证有效期"));
            dt.Columns.Add(new DataColumn("工作人员姓名"));
            dt.Columns.Add(new DataColumn("审批状态"));
            dt.Columns.Add(new DataColumn("审批回复"));
            dt.Columns.Add(new DataColumn("备注"));
            dt.Columns.Add(new DataColumn("配偶姓名"));
            dt.Columns.Add(new DataColumn("配偶身份证号"));
            dt.Columns.Add(new DataColumn("配偶性别"));
            dt.Columns.Add(new DataColumn("配偶出生年月"));
            dt.Columns.Add(new DataColumn("父亲姓名"));
            dt.Columns.Add(new DataColumn("父亲身份证号"));
            dt.Columns.Add(new DataColumn("母亲姓名"));
            dt.Columns.Add(new DataColumn("母亲身份证号"));
            dt.Columns.Add(new DataColumn("子女性别"));
            dt.Columns.Add(new DataColumn("子女出生日期"));
            dt.Columns.Add(new DataColumn("子女姓名"));
            dt.Columns.Add(new DataColumn("子女身份证号"));
            //repositoryItemButtonEdit1.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
            //SgArchiveCommons.commons._uname = "1";
            // DataGridViewButtonColumn viewbutton;
            _listCardinfo = SgAutoArchiveBrrDal.Linq.T_CARDINFO_Dal.Query_SP();
            if (_listCardinfo.Count > 0)
            {
                foreach (var n in _listCardinfo)
                {
                    DataRow row = dt.NewRow();
                    row["ID"] = n.C_ID;
                    row["登记日期"] = n.C_DJDATE;
                    row["档案类型"] = n.C_TYPENAME;
                    row["是否提交"] = n.C_STAUTS;
                    row["姓名"] = n.C_NAME;
                    row["身份证号"] = n.C_CARDNO;
                    row["性别"] = n.C_SEX;
                    row["出生日期"] = n.C_DATE;
                    row["户籍地址"] = n.C_HJADDR;
                    row["所属派出所"] = n.C_DEPARTMENT;
                    row["身份证有效期"] = n.C_YXDATE;
                    row["工作人员姓名"] = n.C_UNAME;
                    row["审批回复"] = n.C_V01;
                    row["备注"] = n.C_V02;
                    if (n.C_I01 == 0)
                    {
                        row["审批状态"] = "尚未审批";
                        SetEditBtn(m_OperateFoodBtn, "审批");
                        //row["审批状态"] = "同意";
                    }
                    if (n.C_I01 == -1)
                    {
                        row["审批状态"] = "不同意";

                    }
                    if (n.C_I01 == 1)
                    {

                        row["审批状态"] = "同意";
                    }

                    row["配偶姓名"] = n.C_PONAME;
                    row["配偶身份证号"] = n.C_PONO;
                    row["配偶性别"] = n.C_POSEX;
                    row["配偶出生年月"] = n.C_PODATE;
                    row["父亲姓名"] = n.C_FANAME;
                    row["父亲身份证号"] = n.C_FANO;
                    row["母亲姓名"] = n.C_MONAME;
                    row["母亲身份证号"] = n.C_MONO;
                    row["子女性别"] = n.C_SONSEX;
                    row["子女出生日期"] = n.C_SONDATE;
                    row["子女姓名"] = n.C_SONNAME;
                    row["子女身份证号"] = n.C_SONNO;
                    dt.Rows.Add(row);

                }
                gridControl1.DataSource = dt;
                gridView1.Columns["ID"].Visible = false;  //设置列为不显示
                gridControl1.RefreshDataSource();
            }
          
            // gridControl1.DataSource = _listCardinfo;
            else
            {
                gridControl1.DataSource = null;
                gridControl1.RefreshDataSource();
                MessageBox.Show("目前数据已经审批完毕，可继续加载数据审批！");
                //DirectoryInfo dir = new DirectoryInfo(Program._lsfilePath);
                //FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();  //返回目录中所有文件和子目录
                //foreach (FileSystemInfo i in fileinfo)
                //{
                //    if (i is DirectoryInfo)            //判断是否文件夹
                //    {
                //        DirectoryInfo subdir = new DirectoryInfo(i.FullName);
                //        subdir.Delete(true);          //删除子目录和文件
                //    }
                //    else
                //    {
                //        File.Delete(i.FullName);      //删除指定文件
                //    }
                //}

               // File.Delete(Program._lsfilePath);
            }
        }


        private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            string cardno = "";
            string path = Program._lsfilePath;
            if (e.Column.FieldName != "审批状态") return;
            DataRow row = gridView1.GetDataRow(e.RowHandle);
            if (row == null) return;
            if (row["审批状态"].ToString() == "尚未审批" && row["是否提交"].ToString() == "2")
            {

                int[] selectedHandle;
                selectedHandle = this.gridView1.GetSelectedRows();
                if (selectedHandle.Length > 0)
                {
                    cardno = this.gridView1.GetRowCellValue(selectedHandle[0], "身份证号").ToString();
                    id = int.Parse(this.gridView1.GetRowCellValue(selectedHandle[0], "ID").ToString());
                }
                _listCardinfo = SgAutoArchiveBrrDal.Linq.T_CARDINFO_Dal.Query_Cardid(id);

                foreach (var n in _listCardinfo)
                {
                    _imagebytescard = n.C_CBMP;
                    _imagebytesper = n.C_PIMG;
                }
                MemoryStream ms = new MemoryStream(_imagebytescard);
                _bit = new Bitmap(ms);
                pictureBox1.Image = _bit;
                MemoryStream ms2 = new MemoryStream(_imagebytesper);
                _bit2 = new Bitmap(ms2);
                pictureBox2.Image = _bit2;

            }

            else {
                MessageBox.Show("请先将数据导出，并在内网查询过再审批！");
            }




            //string cardno = "";
            //string path = Program._lsfilePath;

            //DataRow row = gridView1.GetDataRow(e.RowHandle);
            //if (row == null) return;
            // int[] selectedHandle;
            //    selectedHandle = this.gridView1.GetSelectedRows();
            //    if (selectedHandle.Length > 0)
            //    {
            //       cardno = this.gridView1.GetRowCellValue(selectedHandle[0], "身份证号").ToString();
            //    id=int.Parse( this.gridView1.GetRowCellValue(selectedHandle[0], "ID").ToString());
            //}
            //string pathzj = path + "\\" + cardno + "证件.bmp";
            //string pathrx = path + "\\" + cardno + "人像.jpg";
            //if (File.Exists(pathzj))
            //{
            //    pictureBox1.Load(pathzj);
            //}
            //else { MessageBox.Show(cardno + "的证件照片已丢失或损坏！"); }
            ////BackGroundImageLayout = Stretch，SizeMode = StretchImage
            //if (File.Exists(pathrx))
            //{
            //    pictureBox2.Load(pathrx);
            //}
            //else { MessageBox.Show(cardno + "的人像照片已丢失或损坏！"); }
        }
        public static void getFileName(StreamWriter sw, string path, int indent)
        {
            DirectoryInfo root = new DirectoryInfo(path);
            foreach (FileInfo f in root.GetFiles())
            {
                for (int i = 0; i < indent; i++)
                {
                    sw.Write("  ");
                }
                sw.WriteLine(f.Name);
            }
        }

        public static void getDirectory(StreamWriter sw, string path, int indent)
        {
            getFileName(sw, path, indent);
            DirectoryInfo root = new DirectoryInfo(path);
            foreach (DirectoryInfo d in root.GetDirectories())
            {
                for (int i = 0; i < indent; i++)
                {
                    sw.Write("  ");
                }
                sw.WriteLine("文件夹：" + d.Name);
                getDirectory(sw, d.FullName, indent + 2);
                sw.WriteLine();
            }
        }

        private void btn_drdata_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Multiselect = false;//该值确定是否可以选择多个文件
            dialog.DefaultExt = "zip";
            if (_sUPath != "" && Directory.Exists(_sUPath))
            {
                dialog.InitialDirectory = _sUPath;
            }

            dialog.Title = "请选择文件夹";
            dialog.Filter = "所有文件(*.zip*)|*.zip*";
            string file = "";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                file = dialog.FileName;
            }
            string password = System.Configuration.ConfigurationSettings.AppSettings["password"];
            if (SGZip.DecomparessFile(file, Program._jyfilePath, password))
            { MessageBox.Show("解压完成！"); }
            else { MessageBox.Show("解压失败！"); }
            gridView_init();
        }


        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {




        }

        public static string GetExcelFirstTableName(string connectstring)
        {
            using (OleDbConnection connection = new OleDbConnection(connectstring))
            {
                string tableName = string.Empty;
                if (connection.State == ConnectionState.Closed)
                    connection.Open();
                DataTable dt = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                if (dt != null && dt.Rows.Count > 0)
                {
                    tableName = ConvertTo<string>(dt.Rows[0][2]);
                }
                return tableName;
            }
        }

        public static T ConvertTo<T>(object data)
        {
            if (data == null || Convert.IsDBNull(data))
                return default(T);
            object obj = ConvertTo(data, typeof(T));
            if (obj == null)
            {
                return default(T);
            }
            return (T)obj;
        }

        /// <summary>
        /// 将数据转换为指定类型
        /// </summary>
        /// <param name="data">转换的数据</param>
        /// <param name="targetType">转换的目标类型</param>
        public static object ConvertTo(object data, Type targetType)
        {
            if (data == null || Convert.IsDBNull(data))
            {
                return null;
            }
            Type type2 = data.GetType();
            if (targetType == type2)
            {
                return data;
            }
            if (((targetType == typeof(Guid)) || (targetType == typeof(Guid?))) && (type2 == typeof(string)))
            {
                if (string.IsNullOrEmpty(data.ToString()))
                {
                    return null;
                }
                return new Guid(data.ToString());
            }
            if (targetType.IsEnum)
            {
                try
                {
                    return Enum.Parse(targetType, data.ToString(), true);
                }
                catch
                {
                    return Enum.ToObject(targetType, data);
                }
            }
            if (targetType.IsGenericType)
            {
                targetType = targetType.GetGenericArguments()[0];
            }
            return Convert.ChangeType(data, targetType);
        }
        private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString();
            }
        }
        private void gv_RowCountChanged(object sender, EventArgs e)
        {
            DevExpress.XtraGrid.Views.Grid.GridView gv = (DevExpress.XtraGrid.Views.Grid.GridView)sender;
            if (gv.RowCount < 1000) gv.IndicatorWidth = 35;
            else if (gv.RowCount < 10000) gv.IndicatorWidth = 50;
            else if (gv.RowCount < 100000) gv.IndicatorWidth = 60;
            else if (gv.RowCount < 1000000) gv.IndicatorWidth = 70;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
            gridView1.IndicatorWidth = 40;
            _listCardinfo = SgAutoArchiveBrrDal.Linq.T_CARDINFO_Dal.Query_SP();
            DirectoryInfo dir = new DirectoryInfo(Program._lsfilePath);
            FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();  //返回目录中所有文件和子目录
            foreach (FileSystemInfo i in fileinfo)
            {
                if (i is DirectoryInfo)            //判断是否文件夹
                {
                    DirectoryInfo subdir = new DirectoryInfo(i.FullName);
                    subdir.Delete(true);          //删除子目录和文件
                }
                else
                {
                    File.Delete(i.FullName);      //删除指定文件
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
            if (pictureBox1.Image != null)
            {
            MessageBox.Show("请上传PDF文件并点击确定按钮结束当前审批！");
            this.button3.Visible = true;
            }
            else { MessageBox.Show("请先选择需要审批的记录！"); }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (pictureBox1.Image != null)
            {
                this.txt_bz.Text = "";
               // istauts = -1;
                MessageBox.Show("请在下方补充说明中声明理由并点击确定按钮结束当前审批！");
                this.txt_bz.Visible = true;
                this.button4.Visible = true;
                istauts = -1;
            }
            else { MessageBox.Show("请先选择需要审批的记录！"); }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                if (pictureBox1.Image != null)
                {
                    OpenFileDialog dialog = new OpenFileDialog();
                    dialog.Multiselect = false;//该值确定是否可以选择多个文件
                    dialog.Title = "请选择文件夹";
                    dialog.Filter = "所有文件(*.*)|*.pdf*";
                    string file = "";
                    if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        file = dialog.FileName;
                    }
                    PdfDocument doc = new PdfDocument();
                    doc.LoadFromFile(file);
                    PdfPageBase page = doc.Pages[0];
                  PdfRubberStampAnnotation loStamp = new PdfRubberStampAnnotation(new RectangleF(new PointF(-5, -5), new SizeF(60, 60)));
                    PdfAppearance loApprearance = new PdfAppearance(loStamp);
                    PdfImage image = PdfImage.FromFile(Program._jyfilePath+"\\印章.png");
                    PdfTemplate template = new PdfTemplate(320, 320);
                    template.Graphics.DrawImage(image, 0, 0);
                    loApprearance.Normal = template;
                    loStamp.Appearance = loApprearance;
                    page.AnnotationsWidget.Add(loStamp);
                    string output = Program._jyfilePath +"\\"+id+ ".pdf";
                   doc.SaveToFile(output);
                    FileStream stream = new FileStream(output, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    _imagebytespdf = new byte[stream.Length];
                    stream.Read(_imagebytespdf, 0, (int)stream.Length);
                    stream.Close();
                    T_CARDINFO en = new T_CARDINFO();
                    en.C_STAUTS = 2;//查询电子文件审核中
                    en.c_PDF = _imagebytespdf;
                    //var query = SgAutoArchiveBrrDal.Linq.T_CARDINFO_Dal.Query_Cardid(int.Parse(row["ID"].ToString()));
                    int value = SgAutoArchiveBrrDal.Linq.T_CARDINFO_Dal.Modify_CardPDF(id, en);
                    //SgAutoArchiveBrrDal.Linq.T_CARDINFO_Dal.Modify_Cardinfo();
                    MessageBox.Show("导入PDF成功,请点击确定按钮结束当前审批！");
                    button4.Visible = true;
                    istauts = 1;
                    //File.Delete(file);
                    File.Delete(output);
                   // gridView_init();
                }
                else { MessageBox.Show("请先选择需要审批的记录！"); }

            }
            catch (Exception ex)
            { MessageBox.Show(ex.ToString()); }
        }
        private void SetEditBtn(RepositoryItemButtonEdit btn, string caption)
        {
            btn.Buttons[0].Kind = ButtonPredefines.Glyph;
            btn.Buttons[0].Caption = caption;
            btn.ButtonsStyle = BorderStyles.Simple;
            btn.TextEditStyle = TextEditStyles.HideTextEditor;
        }
        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            // gridView1.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
            gridView1.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("ID"));
            dt.Columns.Add(new DataColumn("登记日期"));
            dt.Columns.Add(new DataColumn("档案类型"));
            dt.Columns.Add(new DataColumn("是否提交"));
            dt.Columns.Add(new DataColumn("姓名"));
            dt.Columns.Add(new DataColumn("身份证号"));
            dt.Columns.Add(new DataColumn("性别"));
            dt.Columns.Add(new DataColumn("出生日期"));
            dt.Columns.Add(new DataColumn("户籍地址"));
            dt.Columns.Add(new DataColumn("所属派出所"));
            dt.Columns.Add(new DataColumn("身份证有效期"));
            dt.Columns.Add(new DataColumn("工作人员姓名"));
            dt.Columns.Add(new DataColumn("审批状态"));
            dt.Columns.Add(new DataColumn("备注"));
            dt.Columns.Add(new DataColumn("配偶姓名"));
            dt.Columns.Add(new DataColumn("配偶身份证号"));
            dt.Columns.Add(new DataColumn("配偶性别"));
            dt.Columns.Add(new DataColumn("配偶出生年月"));
            dt.Columns.Add(new DataColumn("父亲姓名"));
            dt.Columns.Add(new DataColumn("父亲身份证号"));
            dt.Columns.Add(new DataColumn("母亲姓名"));
            dt.Columns.Add(new DataColumn("母亲身份证号"));
            dt.Columns.Add(new DataColumn("子女性别"));
            dt.Columns.Add(new DataColumn("子女出生日期"));
            dt.Columns.Add(new DataColumn("子女姓名"));
            dt.Columns.Add(new DataColumn("子女身份证号"));

            //repositoryItemButtonEdit1.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
            // SgArchiveCommons.commons._uname = "1";
            // DataGridViewButtonColumn viewbutton;
            _listCardinfo = SgAutoArchiveBrrDal.Linq.T_CARDINFO_Dal.Query_SPDC();
            foreach (var n in _listCardinfo)
            {
                DataRow row = dt.NewRow();
                row["ID"] = n.C_ID;
                row["登记日期"] = n.C_DJDATE;
                row["档案类型"] = n.C_TYPENAME;
                row["是否提交"] = n.C_STAUTS;
                row["姓名"] = n.C_NAME;
                row["身份证号"] = n.C_CARDNO;
                row["性别"] = n.C_SEX;
                row["出生日期"] = n.C_DATE;
                row["户籍地址"] = n.C_HJADDR;
                row["所属派出所"] = n.C_DEPARTMENT;
                row["身份证有效期"] = n.C_YXDATE;
                row["工作人员姓名"] = n.C_UNAME;
                if (n.C_I01 == 0)
                { row["审批状态"] = "尚未审批"; }
                if (n.C_I01 == -1)
                {
                    row["审批状态"] = "不同意";
                    //row["审批状态"] = n.C_V01;
                }
                if (n.C_I01 == 1)
                {
                    SetEditBtn(m_OperateFoodBtn, "查阅");
                    row["审批状态"] = "同意";
                }
                row["备注"] = n.C_V02;

                row["配偶姓名"] = n.C_PONAME;
                row["配偶身份证号"] = n.C_PONO;
                row["配偶性别"] = n.C_POSEX;
                row["配偶出生年月"] = n.C_PODATE;
                row["父亲姓名"] = n.C_FANAME;
                row["父亲身份证号"] = n.C_FANO;
                row["母亲姓名"] = n.C_MONAME;
                row["母亲身份证号"] = n.C_MONO;
                row["子女性别"] = n.C_SONSEX;
                row["子女出生日期"] = n.C_SONDATE;
                row["子女姓名"] = n.C_SONNAME;
                row["子女身份证号"] = n.C_SONNO;
                dt.Rows.Add(row);

            }
            //gridView1.Columns.Clear();
            gridControl1.DataSource = dt;
            gridView1.Columns["ID"].Visible = true;  //设置列为不显示
            MessageBox.Show("请选择需要导出的数据并点击确认导出！");


        }

        private void button4_Click(object sender, EventArgs e)
        {
            T_CARDINFO en = new T_CARDINFO();
            en.C_I01 = istauts;
            en.C_STAUTS = 3;
            if (txt_bz.Text != "")
                en.C_V01 = txt_bz.Text;
            //var query = SgAutoArchiveBrrDal.Linq.T_CARDINFO_Dal.Query_Cardid(int.Parse(row["ID"].ToString()));
            int value = SgAutoArchiveBrrDal.Linq.T_CARDINFO_Dal.Modify_CardV01(id, en);
            gridControl1.RefreshDataSource();
           
            gridView_init();
        }

        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.OptionsSelection.MultiSelect = true;
            gridView1.OptionsPrint.PrintSelectedRowsOnly = true;
            gridView1.Columns["ID"].Visible = true;  //设置列为不显示
            gridControl1.RefreshDataSource();
            int[] selectedHandle;
            selectedHandle = this.gridView1.GetSelectedRows();
            if (selectedHandle.Length > 0)
            {
                MessageBox.Show("当前共选择" + selectedHandle.Length + "条数据准备导出！");
                string newfile = Program._spfilePath + "\\" + DateTime.Now.ToString("yyyyMMddHHmmss");
                System.IO.Directory.CreateDirectory(newfile);
                //SaveFileDialog saveFileDialog = new SaveFileDialog();
                //saveFileDialog.Title = "导出Excel";
                //saveFileDialog.Filter = "Excel文件(*.pdf)|*.pdf";
                //saveFileDialog.Filter = "Excel文件(*.xls)|*.xls";
                //saveFileDialog.FileName = newfile + "\\" + "审批数据表.xls";
                //DialogResult dialogResult = saveFileDialog.ShowDialog(this);
                //if (dialogResult == DialogResult.OK)
                //{
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                gridControl1.ExportToXls(newfile + "\\" + "审批数据表.xls", options);
                int[] rownumber = this.gridView1.GetSelectedRows();//获取选中行号；
                int id = 0;
                string cardno = "";
                for (int i = 0; i < this.gridView1.GetSelectedRows().Count(); i++)
                {
                    DataRow row = this.gridView1.GetDataRow(rownumber[i]);//根据行号获取相应行的数据；
                    id = int.Parse(row["ID"].ToString());
                    cardno = row["身份证号"].ToString();
                    T_CARDINFO en = new T_CARDINFO();
                    en.C_STAUTS = 2;//查询电子文件审核中
                  
                    //var query = SgAutoArchiveBrrDal.Linq.T_CARDINFO_Dal.Query_Cardid(int.Parse(row["ID"].ToString()));
                    int value = SgAutoArchiveBrrDal.Linq.T_CARDINFO_Dal.Modify_stauts(id, en);

                    // poldaddr = Program._spfilePath+"\\"+id+".pdf";
                    //string pnewaddr = newfile + "\\" + id + ".pdf";
                    //if (File.Exists(poldaddr))
                    //{
                    //    File.Move(poldaddr, pnewaddr);
                       
                       
                    //}
                }

                string strtxtPath = newfile;
                string strzipPath = newfile + ".zip";
                System.IO.File.SetAttributes(strtxtPath, System.IO.FileAttributes.Normal);
                string password = System.Configuration.ConfigurationSettings.AppSettings["password"];
                SGZip.CompressFile(strtxtPath, strzipPath, null, password, 6);
                Directory.Delete(strtxtPath, true);

                if (_sUPath != "" && Directory.Exists(_sUPath))
                {
                    if (MessageBox.Show("检测到U盘，是否直接将数据包转到U盘中?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
                      == DialogResult.OK)
                    {
                        File.Copy(strzipPath, _sUPath + strzipPath.Substring(strzipPath.LastIndexOf("\\") + 1), true);
                        gridView_init();
                        MessageBox.Show("导出成功并转入U盘中!");
                        return;
                    }
                }

                SaveFileDialog sa = new SaveFileDialog();
                sa.Filter = "*.zip|*.zip";
                if (sa.ShowDialog() == DialogResult.OK)
                {
                    File.Copy(strzipPath, sa.FileName.Substring(0, sa.FileName.LastIndexOf("\\") + 1) +
                        strzipPath.Substring(strzipPath.LastIndexOf("\\") + 1), true);
                }

                gridView_init();
                MessageBox.Show("导出成功！");
                //File.Delete(poldaddr);
            }
        }

        private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView_init();
        }

        private void barButtonItem5_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView_init();
        }
    }
}